﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Transactions;
using AjaxControlToolkitPlus;

public partial class Main_Accounts_VoucherEntry_BillReference : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    int ControlCounter = 2;
    List<string> LstList;
    List<string> LstType;
    List<string> LstDrCr;
    List<string> LstParticular;
    List<string> LstDdlParticular;
    List<string> LstDate;
    List<string> LstDebit;
    List<string> LstCal;
    //List<string> LstHiddebit;
    List<string> LstCredit;
    //List<string> LstHidcredit;
    string credit;
    string debit;
    string strndr;

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        LstList = (List<string>)ViewState["LstList"];
        LstType = (List<string>)ViewState["LstType"];
        LstDrCr = (List<string>)ViewState["LstDrCr"];
        LstParticular = (List<string>)ViewState["LstParticular"];
        LstDdlParticular = (List<string>)ViewState["LstDdlParticular"];
        LstDate = (List<string>)ViewState["LstDate"];
        LstDebit = (List<string>)ViewState["LstDebit"];
        LstCal = (List<string>)ViewState["LstCal"];
        //LstHiddebit = (List<string>)ViewState["LstHiddebit"];
        LstCredit = (List<string>)ViewState["LstCredit"];
        //LstHidcredit = (List<string>)ViewState["LstHidcredit"];
        if(LstList != null)
        {
            int count = Convert.ToInt32(LstList.Count.ToString());
            for (int i = 0; i < count; i++)
            {
                ControlCounter++;
                Label lbl = new Label();
                lbl.ID = LstList[i].ToString();
                lbl.Text = ControlCounter.ToString();
                //Response.Write(" over lbl   " + lbl.ID.ToString() + "</Br>");
                HtmlTableRow htrow = new HtmlTableRow();

                HtmlTableCell htcell1 = new HtmlTableCell();
               // htcell1.ID = "htcell1" + ControlCounter.ToString();
                htcell1.Width = "10%";
                htcell1.VAlign = "Top";
                DropDownList ddltype = new DropDownList();
                ddltype.ID = LstType[i].ToString();
                ddltype.Items.Add(new ListItem("New Bill", "1"));
                ddltype.Items.Add(new ListItem("Towards Bill", "2"));
                ddltype.Items.Add(new ListItem("On A/c", "3"));
                ddltype.SelectedIndex = 0;
                ddltype.Width = Unit.Percentage(98);
                ddltype.AutoPostBack = true;
                ddltype.ToolTip = "New Bill/Towards Bill/On A/c";
                ddltype.SelectedIndexChanged += new EventHandler(ddltype_SelectedIndexChanged);
                ddltype.CssClass = "dropdown";
                htcell1.Controls.Add(ddltype);

                HtmlTableCell htcell2 = new HtmlTableCell();
                htcell2.ID = "htcell2" + ControlCounter.ToString();
                htcell2.Width = "10%";
                htcell2.VAlign = "Top";
                DropDownList ddlDrCr = new DropDownList();
                ddlDrCr.ID = LstDrCr[i].ToString();
                ddlDrCr.Items.Add(new ListItem("Dr", "1"));
                ddlDrCr.Items.Add(new ListItem("Cr", "2"));
                ddlDrCr.SelectedIndex = 0;
                ddlDrCr.Width = Unit.Percentage(98);
                ddlDrCr.AutoPostBack = true;
                ddlDrCr.ToolTip = "Debit/Credit";
                ddlDrCr.SelectedIndexChanged += new EventHandler(ddlDrCr_SelectedIndexChanged);
                ddlDrCr.CssClass = "dropdown";
                htcell2.Controls.Add(ddlDrCr);

                HtmlTableCell htcell3 = new HtmlTableCell();
                htcell3.ID = "htcell3" + ControlCounter.ToString();
                htcell3.Width = "35%";
                htcell3.VAlign = "Top";
                TextBox Txtparticular = new TextBox();
                Txtparticular.ID = LstParticular[i].ToString();
                Txtparticular.Width = Unit.Percentage(98);
                Txtparticular.ToolTip = "Particular";
                DropDownList Ddlparticular = new DropDownList();
                Ddlparticular.ID = LstDdlParticular[i].ToString();
                Ddlparticular.Width = Unit.Percentage(98);
                Ddlparticular.Visible = false;
                htcell3.Controls.Add(Ddlparticular);
                htcell3.Controls.Add(Txtparticular);

                HtmlTableCell htcell4 = new HtmlTableCell();
                htcell4.ID = "htcell4" + ControlCounter.ToString();
                htcell4.Width = "15%";
                htcell4.VAlign = "Top";
                TextBox TxtDate = new TextBox();
                TxtDate.ID = LstDate[i].ToString();
                TxtDate.Width = Unit.Percentage(98);
                TxtDate.ToolTip = "Date";
                TxtDate.Visible = true;
                TxtDate.CssClass = "inputnumber";
                TxtDate.Text = HidDate.Value;
                CalendarExtenderPlus cal = new CalendarExtenderPlus();
                cal.ID= LstCal[i].ToString();
                cal.Format="dd/MM/yyyy";
                cal.TargetControlID = "TxtDate" + ControlCounter.ToString();
                htcell4.Controls.Add(cal);
                htcell4.Controls.Add(TxtDate);

                HtmlTableCell htcell5 = new HtmlTableCell();
                htcell5.ID = "htcell5" + ControlCounter.ToString();
                htcell5.Width = "15%";
                htcell5.VAlign = "Top";
                TextBox TxtDebit = new TextBox();
                TxtDebit.ID = LstDebit[i].ToString();
                TxtDebit.Width = Unit.Percentage(98);
                TxtDebit.ToolTip = "Debit";
                TxtDebit.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event);");
                TxtDebit.Attributes.Add("onfocus", "return RemoveZeroOnFocusDebit(this.id);");
                TxtDebit.Attributes.Add("onblur", "return SetZeroOnBlurDebit(), sumDr();");
                TxtDebit.Visible = true;
                TxtDebit.Enabled = false;
                TxtDebit.CssClass = "inputnumber";
                htcell5.Controls.Add(TxtDebit);

                HtmlTableCell htcell6 = new HtmlTableCell();
                htcell6.ID = "htcell6" + ControlCounter.ToString();
                htcell6.Width = "15%";
                htcell6.VAlign = "Top";
                TextBox TxtCredit = new TextBox();
                TxtCredit.ID = LstCredit[i].ToString();
                TxtCredit.Width = Unit.Percentage(98);
                TxtCredit.ToolTip = "Date";
                TxtCredit.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event);");
                TxtCredit.Attributes.Add("onfocus", "return RemoveZeroOnFocusDebit(this.id);");
                TxtCredit.Attributes.Add("onblur", "return SetZeroOnBlurDebit(), sumCr();");

                TxtCredit.Visible = true;
                TxtCredit.Enabled = false;
                TxtCredit.CssClass = "inputnumber";
                htcell6.Controls.Add(TxtCredit);
                                
                htrow.Cells.Add(htcell1);
                htrow.Cells.Add(htcell2);
                htrow.Cells.Add(htcell3);
                htrow.Cells.Add(htcell4);
                htrow.Cells.Add(htcell5);
                htrow.Cells.Add(htcell6);
                tblVouEntry.Rows.Add(htrow);
            }
         }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        debit = Request.QueryString["debitamt"].ToString();
        credit = Request.QueryString["creditamt"].ToString();
        Txtamt.Text = debit.ToString();
        Txtledger.Text = "Ledger: " +Request.QueryString["ledger"].ToString();
        //HidSum.Value = Request.QueryString["hidval"].ToString();
        HidDrAmt.Value = Request.QueryString["debitamt"].ToString();
        Hidbillamt.Value = Request.QueryString["hidcontrolid"].ToString();

        HidDate.Value = Request.QueryString["Date"].ToString();
        HidLid.Value = Request.QueryString["Ledgerid"].ToString();
        HidLname.Value = Request.QueryString["ledger"].ToString();
        if (!IsPostBack)
        {
            TxtDate2.Text = HidDate.Value;
            TxtDate1.Text = HidDate.Value;
            LstList = new List<string>();
            ViewState["LstList"] = LstList;

            LstType = new List<string>();
            ViewState["LstType"] = LstType;

            LstDrCr = new List<string>();
            ViewState["LstDrCr"] = LstDrCr;

            LstParticular = new List<string>();
            ViewState["LstParticular"] = LstParticular;

            LstDdlParticular = new List<string>();
            ViewState["LstDdlParticular"] = LstDdlParticular;

            LstCal = new List<string>();
            ViewState["LstCal"] = LstCal;

            LstDate = new List<string>();
            ViewState["LstDate"] = LstDate;

            LstDebit = new List<string>();
            ViewState["LstDebit"] = LstDebit;

            LstCredit = new List<string>();
            ViewState["LstCredit"] = LstCredit;

            generatedr();
        }
    }
    protected void AddNewRow()
    {
        //int rowCount = Convert.ToInt32(hidControl.Value);
    
        ControlCounter++;
        Label lbl = new Label();
        lbl.ID = "lbl" + ControlCounter.ToString();
        lbl.Text = ControlCounter.ToString();
        LstList.Add(lbl.ID);

        HtmlTableRow htrow = new HtmlTableRow();

        HtmlTableCell htcell1 = new HtmlTableCell();
       // htcell1.ID = "htcell1" + ControlCounter.ToString();
        htcell1.Width = "10%";
        htcell1.VAlign = "Top";
        DropDownList ddltype = new DropDownList();
        ddltype.ID = "ddltype" + ControlCounter.ToString();
        ddltype.Width = Unit.Percentage(98);
        ddltype.Items.Add(new ListItem("New Bill", "1"));
        ddltype.Items.Add(new ListItem("Towards Bill", "2"));
        ddltype.Items.Add(new ListItem("On A/C", "3"));
        //BindAllItemDropdownlist(dropdown);
        ddltype.AutoPostBack = true;
        ddltype.ToolTip = "New Bill/Towards Bill/On A/C";
        ddltype.SelectedIndexChanged += new EventHandler(ddltype_SelectedIndexChanged);
        ddltype.CssClass = "dropdown";
        htcell1.Controls.Add(ddltype);
        LstType.Add(ddltype.ID);


        HtmlTableCell htcell2 = new HtmlTableCell();
        htcell2.ID = "htcell1" + ControlCounter.ToString();
        htcell2.Width = "10%";
        htcell2.VAlign = "Top";
        DropDownList ddlDrCr = new DropDownList();
        ddlDrCr.ID = "ddlDrCr" + ControlCounter.ToString();
        ddlDrCr.Width = Unit.Percentage(98);
        ddlDrCr.Items.Add(new ListItem("Dr", "1"));
        ddlDrCr.Items.Add(new ListItem("Cr", "2"));
        ddlDrCr.SelectedIndex = 0;
        //BindAllItemDropdownlist(dropdown);
        ddlDrCr.AutoPostBack = true;
        ddlDrCr.ToolTip = "Debit/Credit";
        ddlDrCr.SelectedIndexChanged += new EventHandler(ddlDrCr_SelectedIndexChanged);
        ddlDrCr.CssClass = "dropdown";
        htcell2.Controls.Add(ddlDrCr);
        LstDrCr.Add(ddlDrCr.ID);

        HtmlTableCell htcell3 = new HtmlTableCell();
        htcell3.ID = "htcell3" + ControlCounter.ToString();
        htcell3.Width = "35%";
        htcell3.VAlign = "Top";
        TextBox Txtparticular = new TextBox();
        Txtparticular.ID = "Txtparticular" + ControlCounter.ToString();
        Txtparticular.Width = Unit.Percentage(98);
        Txtparticular.ToolTip = "Particular";
        DropDownList Ddlparticular = new DropDownList();
        Ddlparticular.ID = "Ddlparticular" + ControlCounter.ToString();
        Ddlparticular.Visible = false;
        Ddlparticular.Width = Unit.Percentage(98);
        htcell3.Controls.Add(Ddlparticular);
        LstDdlParticular.Add(Ddlparticular.ID);
        htcell3.Controls.Add(Txtparticular);
        LstParticular.Add(Txtparticular.ID);

        HtmlTableCell htcell4 = new HtmlTableCell();
        htcell4.ID = "htcell4" + ControlCounter.ToString();
        htcell4.Width = "15%";
        htcell4.VAlign = "Top";
        TextBox TxtDate = new TextBox();
        TxtDate.ID = "TxtDate" + ControlCounter.ToString();
        TxtDate.Width = Unit.Percentage(98);
        TxtDate.ToolTip = "Date";
        TxtDate.Text = "";
        TxtDate.CssClass = "inputnumber";
        TxtDate.Visible = true;
        TxtDate.Text = HidDate.Value;
        CalendarExtenderPlus cal = new CalendarExtenderPlus();
        cal.ID = "CalendarExtenderPlus" + ControlCounter.ToString();
        cal.Format="dd/MM/yyyy";
        cal.TargetControlID = "TxtDate" + ControlCounter.ToString();
        htcell4.Controls.Add(cal);
        LstCal.Add(cal.ID);

        htcell4.Controls.Add(TxtDate);
        LstDate.Add(TxtDate.ID);

        HtmlTableCell htcell5 = new HtmlTableCell();
        htcell5.ID = "htcell5" + ControlCounter.ToString();
        htcell5.Width = "15%";
        htcell5.VAlign = "Top";
        TextBox TxtDebit = new TextBox();
        TxtDebit.ID = "TxtDebit" + ControlCounter.ToString();        
        TxtDebit.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event);");
        TxtDebit.Attributes.Add("onfocus", "return RemoveZeroOnFocusDebit(this.id);");
        TxtDebit.Attributes.Add("onblur", "return SetZeroOnBlurDebit(), sumDr();");
        TxtDebit.CssClass = "inputnumber";
        TxtDebit.Width = Unit.Percentage(98);
        TxtDebit.ToolTip = "Date";       
        TxtDebit.Visible = true;
        TxtDebit.Enabled = false;
        htcell5.Controls.Add(TxtDebit);
        LstDebit.Add(TxtDebit.ID);

        HtmlTableCell htcell6 = new HtmlTableCell();
        htcell6.ID = "htcell6" + ControlCounter.ToString();
        htcell6.Width = "15%";
        htcell6.VAlign = "Top";
        TextBox TxtCredit = new TextBox();
        TxtCredit.ID = "TxtCredit" + ControlCounter.ToString();
        TxtCredit.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event);");
        TxtCredit.Attributes.Add("onfocus", "return RemoveZeroOnFocusDebit(this.id);");
        TxtCredit.Attributes.Add("onblur", "return SetZeroOnBlurDebit(), sumCr();");
        TxtCredit.Width = Unit.Percentage(98);
        TxtCredit.CssClass = "inputnumber";
        TxtCredit.ToolTip = "Date";
       
        TxtCredit.Visible = true;
        TxtCredit.Enabled = false;
        htcell6.Controls.Add(TxtCredit);
        LstCredit.Add(TxtCredit.ID);

        htrow.Cells.Add(htcell1);
        htrow.Cells.Add(htcell2);
        htrow.Cells.Add(htcell3);
        htrow.Cells.Add(htcell4);
        htrow.Cells.Add(htcell5);
        htrow.Cells.Add(htcell6);
        tblVouEntry.Rows.Add(htrow);

        ViewState["LstList"] = LstList;
        ViewState["LstType"] = LstType;
        ViewState["LstDrCr"] = LstDrCr;
        ViewState["LstParticular"] = LstParticular;
        ViewState["LstDdlParticular"] = LstDdlParticular;
        ViewState["LstDate"] = LstDate;
        ViewState["LstDebit"] = LstDebit;
        ViewState["LstCredit"] = LstCredit;
        hidControl.Value = ControlCounter.ToString();
       // BindLedger_ForDebitAndCredit(ddlDrCr.SelectedIndex, ControlCounter);
    }
    protected void btnAddRow_Click(object sender, EventArgs e)
    {
        AddNewRow();
    }
    protected void ddlDrCr_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(7);
        int rowIndex = Convert.ToInt32(ddlid.ToString());
        TextBox txtDebit = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("txtDebit" + rowIndex);
        TextBox txtCredit = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("txtCredit" + rowIndex);

        DropDownList Ddlparticular = (DropDownList)tblVouEntry.Rows[rowIndex].FindControl("Ddlparticular" + rowIndex);
        DropDownList ddlDrCr = (DropDownList)tblVouEntry.Rows[rowIndex].FindControl("ddlDrCr" + rowIndex);

        if (ddl.SelectedValue == "1")
        {
            txtDebit.Enabled = true;
            txtDebit.Text = "0.00";
            txtCredit.Text = "";
            txtCredit.Enabled = false;
            bindmain(Ddlparticular, ddlDrCr);
           
        }
        else if (ddl.SelectedValue == "2")
        {
            txtDebit.Text = "";
            txtDebit.Enabled = false;
            txtCredit.Enabled = true;
            txtCredit.Text = "0.00";
            bindmain(Ddlparticular, ddlDrCr);
        }
    }
    protected void ddltype_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(7);
        int rowIndex = Convert.ToInt32(ddlid.ToString());
        TextBox Txtparticular = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("Txtparticular" + rowIndex);
        DropDownList Ddlparticular = (DropDownList)tblVouEntry.Rows[rowIndex].FindControl("Ddlparticular" + rowIndex);
        DropDownList ddlDrCr = (DropDownList)tblVouEntry.Rows[rowIndex].FindControl("ddlDrCr" + rowIndex);
        TextBox txtDebit = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("txtDebit" + rowIndex);
        TextBox txtCredit = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("txtCredit" + rowIndex);
        TextBox txtDate = (TextBox)tblVouEntry.Rows[rowIndex].FindControl("TxtDate" + rowIndex);
        if (ddl.SelectedValue == "1")
        {
          
            Txtparticular.Visible = true;
            Txtparticular.Enabled = true;
            Ddlparticular.Visible = false;
            Txtparticular.Text = "";
            //txtCredit.Enabled = true;
           // txtDebit.Enabled = true;
            //txtDate.Enabled = true;
            txtDate.Text = HidDate.Value;
            txtCredit.Text = "0.00";
            txtDebit.Text = "0.00";
        }
        else if (ddl.SelectedValue == "2")
        {
            Ddlparticular.Visible = true;
            Ddlparticular.Enabled = true;
           
            Txtparticular.Visible = false;
            Txtparticular.Text = "";
            //txtDate.Enabled = true;
            txtDate.Text = HidDate.Value;
            txtCredit.Text = "0.00";
            txtDebit.Text = "0.00";
            if (ddlDrCr.SelectedValue == "1")
            {
                bindmain(Ddlparticular, ddlDrCr);
            }
            else if (ddlDrCr.SelectedValue == "2")
            {
                bindmain(Ddlparticular, ddlDrCr);
            }
        }
        else if(ddl.SelectedValue == "3")
        {
            Txtparticular.Visible = true;
            Txtparticular.Enabled = false;
            Ddlparticular.Visible = false;
            Txtparticular.Text = "";
           // txtCredit.Enabled = true;
           // txtDebit.Enabled = true;
           // txtDate.Enabled = false;
            txtDate.Text = HidDate.Value;
            txtCredit.Text = "0.00";
            txtDebit.Text = "0.00";
        }
    }

    protected void bindmain(DropDownList ddl, DropDownList ddltype)
    {


        //DropDownList ddltype = (DropDownList)tblVouEntry.FindControl("ddlDrCr");
      

        string[] Splitdate = HidDate.Value.Split('/');
        string Dateformat = Splitdate[1].ToString() + "/" + Splitdate[0].ToString() + "/" + Splitdate[2].ToString();
        SqlParameter[] parm = { 
                                  new SqlParameter("@LedgerID",HidLid.Value),
                                  new SqlParameter("@TransactionDate",Dateformat),
                                  new SqlParameter("@TranID","0"),
                                  new SqlParameter("@RefType","1"),
                              };
        //lblmsg.Text = HidDate.Value.ToString();
        DataTable dt = DU.getdatausingprocedure("USP_ACC_GetPendingReferenceDetails", parm);
        DataView dv = dt.DefaultView;
        string drcr=ddltype.SelectedValue;
        if (drcr == "1")
        {
            dv.RowFilter = "DrCrBalance ='Dr'";
        }
        else if (drcr == "2")
        {
            dv.RowFilter = "DrCrBalance ='Cr'";
        }
        //if (dt.Rows.Count > 0)
        //{
            ddl.DataSource = dv;
            ddl.DataTextField = "Particulars";
            ddl.DataValueField = "RefID";
            ddl.DataBind();
        //}
    }

   
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //SaveRefDetail();
    }

    protected void DeleteLastRow()
    {
        int rowCount = Convert.ToInt32(hidControl.Value);
        int rowIndex = rowCount;
        for (int i = 0; i < tblVouEntry.Rows.Count; i++)
        {
            if (i > 2)
            {
                if (rowCount == i)
                {
                    tblVouEntry.Rows.RemoveAt(rowCount);
                    rowIndex = rowCount - 1;
                    LstList.RemoveAt(rowCount - 3);
                    LstType.RemoveAt(rowCount - 3);
                    LstDrCr.RemoveAt(rowCount - 3);
                    LstParticular.RemoveAt(rowCount - 3);
                    LstDdlParticular.RemoveAt(rowCount - 3);
                    LstDate.RemoveAt(rowCount - 3);
                    LstDebit.RemoveAt(rowCount - 3);
                    LstCal.RemoveAt(rowCount - 3);
                    LstCredit.RemoveAt(rowCount - 3);

                    ViewState["LstList"] = LstList;
                    ViewState["LstType"] = LstType;
                    ViewState["LstDrCr"] = LstDrCr;
                    ViewState["LstParticular"] = LstParticular;
                    ViewState["LstDdlParticular"] = LstDdlParticular;
                    ViewState["LstDate"] = LstDate;
                    ViewState["LstDebit"] = LstDebit;
                    ViewState["LstCal"] = LstCal;
                    ViewState["LstCredit"] = LstCredit;
                    hidControl.Value = rowIndex.ToString();
               
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "SetZeroOnBlurDebit(); SetZeroOnBlurCredit();", true);
                }
            }
        }
    }

    protected void generatedr()
    {
        double totalDramt = 0;
        double totalCramt = 0;
        string[] dramt = Request.QueryString["hidval"].ToString().Split(':');
        if (dramt.Length > 1)
        {
            string[] drcelltxtamt = dramt[0].Split('|');
            string[] celltype = dramt[1].Split('|');
            string[] DrCrcell = dramt[2].Split('|');
            string[] SelectTxtParticular = dramt[4].Split('-');
            string[] SelectDdlParticular = dramt[3].Split('|'); //present the value of dropdown
            string[] SelectDate = dramt[5].Split('|');
            string[] SelectDdlparticulartext = dramt[6].Split('|'); //present the Text of dropdown
            string[] SelectCredit= dramt[7].Split('|'); 
            // lblmsg.Text = dramt[6].ToString(); 
            //lblmsg.Text = SelectDdlParticular.Length.ToString();
            for (int j = 0; j < drcelltxtamt.Length - 1; j++) // drtxramt.Length = 3
            {
                if (j > 1)
                {
                    AddNewRow();
                }
                TextBox txtDebit = (TextBox)tblVouEntry.FindControl("TxtDebit" + (j + 1));
                TextBox txtCredit = (TextBox)tblVouEntry.FindControl("TxtCredit" + (j + 1));
                DropDownList ddltype = (DropDownList)tblVouEntry.FindControl("ddltype" + (j + 1));
                DropDownList ddlDrCr = (DropDownList)tblVouEntry.FindControl("ddlDrCr" + (j + 1));
               TextBox TxtDate = (TextBox)tblVouEntry.FindControl("TxtDate" + (j + 1));
               TextBox Txtparticular = (TextBox)tblVouEntry.FindControl("Txtparticular" + (j + 1));
                DropDownList Ddlparticular = (DropDownList)tblVouEntry.FindControl("Ddlparticular" + (j + 1));

               
              
                ddltype.SelectedValue = celltype[j].ToString();
                ddlDrCr.SelectedValue = DrCrcell[j].ToString();

               
                TxtDate.Text = SelectDate[j].ToString();
               

               

                if (ddltype.SelectedValue == "1")
                {
                    Ddlparticular.Visible = false;
                    Txtparticular.Visible = true;
                    Txtparticular.Enabled = true;
                    Txtparticular.Text = SelectTxtParticular[j].ToString();
                    
                   
                    //txtCredit.Enabled = true;
                    //txtDebit.Enabled = true;
                    //txtDate.Enabled = true;
                    //txtDate.Text = HidDate.Value;
                    //txtCredit.Text = "0.00";
                    //txtDebit.Text = "0.00";
                }
                else if (ddltype.SelectedValue == "2")
                {
                    Txtparticular.Visible = false;
                    Ddlparticular.Visible = true;
                    Ddlparticular.Enabled = true;
                    if (ddlDrCr.SelectedValue == "1")
                    {
                        bindmain(Ddlparticular, ddlDrCr);
                    }
                    else if (ddlDrCr.SelectedValue == "2")
                    {
                        bindmain(Ddlparticular, ddlDrCr);
                    }
                    if (SelectDdlParticular[j].Length > 0)
                    {
                        Ddlparticular.SelectedValue = SelectDdlParticular[j].ToString();
                        //lblmsg.Text = "abc";
                    }
                    TxtDate.Enabled = true;
                   
                }
                else if (ddltype.SelectedValue == "3")
                {
                    Ddlparticular.Visible = false;
                    Txtparticular.Visible = true;
                    Txtparticular.Enabled = false;
                    Txtparticular.Text = "";
                    TxtDate.Enabled = false;
                }
                if (ddlDrCr.SelectedValue == "1")
                {
                    txtDebit.Enabled = true;
                    txtCredit.Enabled = false;
                    txtCredit.Text = "";
                    txtDebit.Text = drcelltxtamt[j].ToString();
                    totalDramt += Convert.ToDouble(txtDebit.Text);
                }
                if (ddlDrCr.SelectedValue == "2")
                {
                    txtDebit.Enabled = false;
                    txtCredit.Enabled = true;
                    txtDebit.Text = "";
                    txtCredit.Text = SelectCredit[j].ToString();
                    totalCramt += Convert.ToDouble(txtCredit.Text);
                }


            }
            txtTotalDebit.Text =string.Format("{0:0.00}", totalDramt.ToString());
            txtTotalCredit.Text = string.Format("{0:0.00}", totalCramt.ToString());
           
        }
    }
    protected void btnDeleteRow_Click(object sender, EventArgs e)
    {
        DeleteLastRow();
    }
}
